package com.sl.service;

import com.sl.mapper.RouteMapper;
import com.sl.pojo.Route;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: weilai
 * @date: 2020/2/6
 * @description:
 */
@Service
public class RouteService {

    @Resource
    private RouteMapper routeMapper;

    public List<Route> findAll(){
        Example example = new Example(Route.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("pId",0);
        return routeMapper.selectByExample(example);
    }

    public Route findById(Integer id){
       return routeMapper.selectByPrimaryKey(id);
    }
    public List<Route> findByPid(Integer pId){
        Example example = new Example(Route.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("pId",pId);
        List<Route> routes = routeMapper.selectByExample(example);
        return routes;
    }


    /**增加
     */
    public void add(Route route){
        routeMapper.insert(route);
    }
    /**
     * 修改
     */
    public void update(Route route){
        routeMapper.updateByPrimaryKey(route);
    }
    /**
     * 真实删除
     */
    public void deleteReal(Integer id){
        routeMapper.deleteByPrimaryKey(id);
    }
}
